import Vue from 'vue'
import './plugins/axios'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'
import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'

Vue.config.productionTip = false
 Vue.use(VXETable)

// 全局前置守卫
let isRedirected = false;
 
router.beforeEach((to, from, next) => {
  const token = localStorage.getItem('token');
  const isLoggedIn = token !== null;//token不为空===true
 
  if (!isLoggedIn && !isRedirected) {
	  //token为空
    isRedirected = true;
    next('/login');
  } else if (isLoggedIn && to.path === '/login') {
	 next();
  } else{
	next();
  }
});



new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

